﻿@{
    Layout = "~/Areas/Web/Views/Shared/_UserCenter.cshtml";
    ViewBag.Title = "投诉维权";
}
@model IEnumerable<Himall.Model.OrderInfo>

<div class="box1 lh24">
    <div class="title">
        <span class="title_txt curr">投诉维权</span>
        <span class="title_txt"><a href="@Url.Action("Record")">申请记录</a></span>
    </div>
    <div class="border-box">
        <table class="tb-void tb-back">
            <colgroup>
                <col width="180" />
                <col width="430" />
                <col width="130" />
                <col width="120" />
            </colgroup>
            <thead>
                <tr class="tr">
                    <th>订单编号</th>
                    <th>订单商品</th>
                    <th>下单时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @if (Model.Count() == 0)
                {
                    <tr><td colspan="4"><div class="empty"><b></b>暂时没有记录！</div></td></tr>
                }
                @foreach (var m in Model)
                {
                    <tr class="tr-td">
                        <td>
                            <span class="col-blue">
                                @m.Id @if (m.UserId != ViewBag.UserId)
                                {<label>(子订单)</label>}
                            </span>
                        </td>
                        <td>
                            <ul class="back-goods-list">
                                @foreach (var item in m.OrderItemInfo)
                                {
                                    var spc = "";
                                    if (!string.IsNullOrWhiteSpace(item.Color)) { spc += "颜色：" + item.Color; }
                                    if (!string.IsNullOrWhiteSpace(item.Size)) { spc += "，尺寸：" + item.Size; }
                                    if (!string.IsNullOrWhiteSpace(item.Version)) { spc += "，版本：" + item.Version; }
                                    <li>
                                        <a href="/product/detail/@item.ProductId" title="@item.ProductName 【@spc.TrimStart('，')】"><img width="50" height="50" alt="" src="@item.ThumbnailsUrl" /></a>
                                    </li>
                                }
                            </ul>
                        </td>
                        <td>
                            <span class="ftx-03"> @m.OrderDate</span>
                        </td>
                        @if (m.UserId == ViewBag.UserId)
                        {
                            if (m.OrderComplaintInfo.Count() > 0 && string.IsNullOrWhiteSpace(m.OrderComplaintInfo.ElementAt(0).SellerReply))
                            {
                                <td><a class="btn-5" href="javascript:void(0)">等待商家处理</a></td>
                            }
                            else if (m.OrderComplaintInfo.Count() > 0 && !string.IsNullOrWhiteSpace(m.OrderComplaintInfo.ElementAt(0).SellerReply))
                            {
                                <td>
                                    <a class="btn-5" href="javascript:void(0)">
                                        商家处理结果：@m.OrderComplaintInfo.ElementAt(0).SellerReply
                                    </a>
                                </td>
                            }
                            else
                            {
                                <td><a class="complain-btn btn-5" href="javascript:AddComplain('@m.ShopId','@m.Id')">我要投诉</a></td>
                            }
                        }
                    </tr>
                }
            </tbody>

        </table>
        <div class="cl mt10" id="bottom_pager">
            <div id="pagin-btm" class="pagin fr" style="clear:both">
                @{
                    var count = ((PagingInfo)ViewBag.pageInfo).TotalPages;
                    var curr = ((PagingInfo)ViewBag.pageInfo).CurrentPage;
                }
                @Html.PageLinks((PagingInfo)ViewBag.pageInfo, x => Url.Action("Index", new { pageNo = x }))
                <span class="page-skip">
                    <em>&nbsp;&nbsp;共 @count 页&nbsp;&nbsp;&nbsp;&nbsp;</em>
                </span>
            </div>
        </div>
    </div>

</div>


<div class="dialog-form" id="addform" style="display:none">
    <div class="mc">
        <div class="form">
            <div class="item">
                <span class="label">投诉内容：</span>
                <div class="fl">
                    <textarea class="area" id="content" cols="50" rows="4"></textarea>
                </div>
                <div class="clr"></div>
            </div>
            <div class="item">
                <span class="label">联系电话：</span>
                <div class="fl">
                    <input type="text" id="UserPhone" class="text" value="@ViewBag.UserPhone" />
                </div>
                <div class="clr"></div>
            </div>
        </div>
    </div>

</div>


<script type="text/javascript">
    function AddComplain(shopId, orderId) {
        $.dialog({
            title: '我要投诉',
            lock: true,
            id: 'ChangePwd',
            width: '500px',
            content: document.getElementById("addform"),
            padding: '20px 10px',
            okVal: '确认投诉',
            init: function () { $("#content").focus(); },
            ok: function () {
                var complaint = $("#content").val();
                complaint = complaint.replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/\n/g, "&nbsp;").replace("'", "‘").replace('"', "“");
                var phone = $("#UserPhone").val();
                if (complaint.length < 5) {
                    $.dialog.errorTips("投诉原因不能小于五个字符！", '', 1);
                    return false;
                }
                else if (phone == "") {
                    $.dialog.errorTips("投诉电话不能为空！", '', 1);
                    return false;
                }
                var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
                if ( !reg.test( phone ) )
                {
                    $.dialog.errorTips( "电话格式错误！", '', 1 );
                    return false;
                } 
                var loading = showLoading();
                $.ajax({
                    type: 'POST',
                    url: '/OrderComplaint/AddOrderComplaint',
                    cache: false,
                    data: { "ComplaintReason": complaint, "UserPhone": phone, "ShopId": shopId, "OrderId": orderId },
                    dataType: 'json',
                    success: function (data) {
                        loading.close();
                        if (data.success) {
                            $.dialog.succeedTips("提交成功！", function () {
                                window.location.href = window.location.href;
                            }, 1);

                        }
                        else {
                            $.dialog.errorTips("提交失败！" + data.msg, '', 2);
                        }
                    },
                });
            }
        });
    }
</script>